package com.example.cxx.Utils;

import java.util.HashMap;

public class CookieUtil {
    public static HashMap<String, String> convertCookie(String cookie) {
        HashMap<String, String> cookiesMap = new HashMap<String, String>();
        //输出的是标点key,value
        String cookies=cookie.substring(1,cookie.length()-1);
        //用逗号分隔
        String[] items = cookies.trim().split(",");
        for (String item : items) {
           String key=item.split(":")[0].substring(1,item.split(":")[0].length()-1);
           String value=item.split(":")[1].substring(1,item.split(":")[1].length()-1);
           cookiesMap.put(key,value);
        }
        return cookiesMap;
    }
    public static HashMap<String, String> convertCookie2(String cookie) {
        HashMap<String, String> cookiesMap = new HashMap<String, String>();
        //输出的是标点key,value
        String cookies=cookie.substring(1,cookie.length()-1);
        //用逗号分隔
        String[] items = cookies.trim().split(",");
        for (String item : items) {
            String key=item.split("=")[0];
            String value;
            try{
                 value=item.split("=")[1];
            }catch (Exception e){
                 value="";
            }
            cookiesMap.put(key,value);
        }
        return cookiesMap;
    }

}
